<?php

namespace app\traits;

use think\response\Json;

trait ApiResponseTrait
{
    public function success($data = [], $msg = '请求成功', $code = 1): Json
    {
        $response = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
        return json($response)->code(200);
    }

    public function error($msg, $code = 0): Json
    {
        $response = [
            'code' => $code,
            'msg' => $msg,
            'data' => []
        ];
        return json($response)->code(200);
    }
}